package edu.calpoly.lab7;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;

public class AccelActivity extends Activity implements SensorEventListener {

	public static final int ACC_X = 0;
	public static final int ACC_Y = 1;
	public static final int ACC_Z = 2;
	
	private SensorManager sensorManager;
	private Sensor accelerometer;

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.accel);
		registerWithSensor();
    }
	
	private void registerWithSensor() {
		this.sensorManager = (SensorManager)this.getSystemService(Context.SENSOR_SERVICE);
		this.accelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		this.sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
	}

	public void onSensorChanged(SensorEvent event) {
		((TextView)this.findViewById(R.id.accelerationX)).setText(String.valueOf(event.values[0]));
		((TextView)this.findViewById(R.id.accelerationY)).setText(String.valueOf(event.values[1]));
		((TextView)this.findViewById(R.id.accelerationZ)).setText(String.valueOf(event.values[2]));
	}
	
	public void onAccuracyChanged(Sensor sensor, int accuracy) { }
}
